﻿#ifndef HEARTBEATMANAGER_H
#define HEARTBEATMANAGER_H

#include <qobject.h>
#include "ObjAutoInject.h"
#include <qtimer.h>


class TcpIOer;
class TcpCodec;
class UserRegisterCodec;
class HeartBeatManager : public QObject,public ObjAutoInject
{
  Q_OBJECT
private://property
  uint interval=10*1000;
  uint timeout=33*1000;//比超时时间的三倍多一点，预防网络波动
  QTimer timer_sendHeartBeat;
private://dependency
  TcpIOer* tcpIOer=Q_NULLPTR;
  TcpCodec* tcpCodec=Q_NULLPTR;
  UserRegisterCodec* userRegisterCodec=Q_NULLPTR;
public:
  explicit HeartBeatManager();
  virtual ~HeartBeatManager();
signals:
public:
  void updateHeartBeat();
private slots:
  void slot_registerStateChanged(uchar state);
  void slot_disconnected();
  void slot_sendHeartBeat();
public://geter and seter
  TcpIOer* getTcpIOer()const;
  HeartBeatManager* setTcpIOer(TcpIOer*const tcpIOer);
  TcpCodec* getTcpCodec()const;
  HeartBeatManager* setTcpCodec(TcpCodec*const tcpCodec);
  UserRegisterCodec* getUserRegisterCodec()const;
  HeartBeatManager* setUserRegisterCodec(UserRegisterCodec* const userRegisterCodec);
public:
  virtual void objectAutoInjection(QHash<QString,QObject*>* objMap)override;
};

#endif // HEARTBEATMANAGER_H
